package com.puzzlebazar.client.squaregrid.view;

import com.puzzlebazar.client.util.Vec2i;

public class CellHighlighterBasic implements CellHighlighter {

	private final DrawableLayer layer;
	private final String style;
	private final String name;
	
	private int bleed = 0;

	
	/**
	 * Create an object that is able to highlight cells of a square grid using
	 * a standard square highlight.
	 * 
	 * @param layer The layer into which to put drawables resulting from highlighting
	 * @param style The style to use for highlighting  (can be a space separated list)
	 * @param name The name to use for highlighting drawables
	 */
	public CellHighlighterBasic( DrawableLayer layer, String style, String name ) {
		this.layer = layer;
		this.style = style;
		this.name = name;
	}
	
	@Override
	public void highlightCell(Vec2i loc) throws Exception {
		Drawable drawable = new FillDrawable(loc,name,style);
		drawable.setBleed( bleed );
		layer.addDrawable( drawable );
	}

	@Override
	public void highlightCells(Vec2i loc1, Vec2i loc2) throws Exception {
		Drawable drawable = new FillDrawable(name,style);
		drawable.setCellRectangle(loc1, loc2);
		drawable.setBleed( bleed );
		layer.addDrawable( drawable );
	}
	
	@Override
	public void unhighlightCell(Vec2i loc) throws Exception {
		layer.removeCellDrawable(loc, name);
	}

	@Override
	public void unhighlightCells(Vec2i loc1, Vec2i loc2) throws Exception {
		layer.removeCellDrawable(loc1, loc2, name);
	}
	
	@Override
	public void unhighlightAllCells() {
		layer.removeDrawable(name);
	}

	/**
	 * Sets the size, in pixel, of the expansion around the selected cell.
	 * Use a negative number to shrink the size of the highlighted cell.
	 * 
	 * @param bleed The size, in pixel
	 */
	public void setBleed( int bleed ) {
		this.bleed = bleed;
	}

}
